﻿using EFMVC.AchieveInterface;
using EFMVC.EDMX;
using EFMVC.Interface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EFMVC.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            EFMVC.Interface.IBaseReposity<Sys_User> sysUserReposty = new BaseReposity<Sys_User>(new TPYEntities1());

            //using (TPYEntities1 entity = new TPYEntities1())
            //{
            //    listUser = (from user in entity.Sys_User
            //                select user).ToList();
            //}
            var listUser = sysUserReposty.Get(filter: m => m.Account == "lisi", orderBy: q => q.OrderBy(m => m.Name));
            //var listUser = sysUserReposty.Get(orderBy: q => q.OrderBy(m => m.Account));
            return View(listUser);
        }

        public ActionResult Add()
        {
            Sys_User user = new Sys_User();
            Guid id = new Guid("93a27624-9350-48ed-8a8b-e7651ae1918d");
            using (TPYEntities1 entity = new TPYEntities1())
            {
                user = (from userInfo in entity.Sys_User
                        where userInfo.ID==id
                        select userInfo).FirstOrDefault();
                if (user != null)
                {
                    entity.Entry<Sys_User>(user).State = EntityState.Deleted;
                    entity.SaveChanges();
                }
            }
            return View(user);
        }
        public ActionResult GetResult()
        {
            return View();
        }

    }
}
